Geospatial Data Science

Lecture 11: Individual mobility

IT University of Copenhagen, Spring 2022

Instructor: Michael Szell

Source

This notebook was adapted from:

What is scikit-mobility?

a library to analyze *mobility data*, suited for working with:

scikit-mobility provides two user-friendly data structures that extends the pandas DataFrame:

What you can do with scikit-mobility?

TrajDataFrame

Each row describes a trajectory's point and contains the following columns:

For multi-user data sets, there are two optional columns:

A TrajDataFrame can be created from:

From a list

We must set the indexes of the mandatory columns using arguments latitude, longitude and datetime.

From a DataFrame

Note that:

From a text file

Class TrajDataFrame has a method from_file to construct the object from an input text file.

Let's try with a subsample of the **GeoLife** trajectories. The whole dataset can be found here.

Attributes of a TrajDataFrame

Columns of TrajDataFrame have specific types

Write and read

To write/read a TrajDataFrame into a file, scikit-mobility provides ad-hoc methods.

Writing a TrajDataFrame to a file

Read a TrajDataFrame from a json file

dtypes and the parameters and crs attributes are preserved

Plotting trajectories and flows

scikit-mobility relies on the folium library to plot:

FlowDataFrame

Each row describes a flow and contains the columns:

Tessellation

Each FlowDataFrame is associated with a **tessellation**, i.e., a GeoDataFrame that contains two columns:

Create of a FlowDataFrame

The FlowDataFrame can be created from:

From a file

method from_file creates a FlowDataFrame from a text file with the format:

Plot the tessellation

Plot the flows

Plot tessellation and flows

Mobility measures

Individual measures

Radius of gyration $r_g$

characteristic distance traveled by an individual:

$$r_g = \sqrt{\frac{1}{N} \sum_{i=1}^N (\mathbf{r}_i - \mathbf{r}_{cm})^2}$$

$r_{cm}$ is the position vector of the center of mass of the set of locations visited by the individual

Jump lengths

Distances

Individual mobility network

a network where:

Collective measures

Visits per location

number of visits to a location made by the population of individuals

Many many other measures can be computed with scikit-mobility.

Just check the documentation https://scikit-mobility.github.io/scikit-mobility/reference/measures.html